// 打包库时提供的文件

#include "ymbxlog.hpp"


// 提供用户更方便使用的接口
namespace ymbxlog
{
    enum LoggerField{
        LOGGER_LOCAL,
        LOGGER_GLOBAL
    };
    // 创建日志器接口：
        // name  日志器名
        // lev   日志器输出限制等级（≥lev输出）
        // lfd   日志器是全局还是局部
        // pattern   格式化输出字符串样式
        // sinks 落地方式
        // loggertype 日志器类型（同步/异步）

    Logger::ptr GetLogger(const std::string &name)
    {
        return LoggerManager::GetInstance().GetLoggerByName(name);
    }
    Logger::ptr GetRootLogger()
    {
        return LoggerManager::GetInstance().GetRootLoggerByName();
    }
    Logger::ptr CreatLogger(const std::string& name,const std::string& pattern,LogLevel::Level lev,LoggerField lfd, LoggerType loggertype){
        std::unique_ptr<LoggerBuilder> logger(nullptr);        
        if(lfd==LoggerField::LOGGER_LOCAL){
            logger.reset(new LocalLoggerBuild());
        }else{
            logger.reset(new GlobalLoggerBuild());
        }   
        logger->BuildLoggername(name);
        logger->BuildLimitLevel(lev);
        logger->BuildFormatter(pattern);
        if(loggertype==LoggerType::LOGGER_SYNC){
            logger->EnableLoggerSync();
        }else{
            logger->EnableLoggerAsync();
        }
        return logger->Build();
    }
    // 为指定name的日志器添加日志落地模块
    template<typename SinkType,typename... Args>
    void AddSinkByname(const std::string& name,Args&& ...args){
        if(!LoggerManager::GetInstance().IsExist(name)){
            std::cout<<"日志器不存在，请先创建日志器\n";
        }
        Logger::ptr logger=GetLogger(name);
        logger->AddSink(std::make_shared<SinkType>(std::forward<Args>(args)...));
    }

    Logger::ptr CreatSyncLocalLogger(const std::string& name,const std::string& pattern,LogLevel::Level lev){
        return CreatLogger(name,pattern,lev,LoggerField::LOGGER_LOCAL,LoggerType::LOGGER_SYNC);
    }
    Logger::ptr CreatSyncGlobalLogger(const std::string& name,const std::string& pattern,LogLevel::Level lev){
        return CreatLogger(name,pattern,lev,LoggerField::LOGGER_GLOBAL,LoggerType::LOGGER_SYNC);
    }
    Logger::ptr CreatAsyncLocalLogger(const std::string& name,const std::string& pattern,LogLevel::Level lev){
        return CreatLogger(name,pattern,lev,LoggerField::LOGGER_LOCAL,LoggerType::LOGGER_ASYNC);
    }
    Logger::ptr CreatAsyncGLobalLogger(const std::string& name,const std::string& pattern,LogLevel::Level lev){
        return CreatLogger(name,pattern,lev,LoggerField::LOGGER_GLOBAL,LoggerType::LOGGER_ASYNC);
    }

    Logger::ptr CreatSyncLocalLogger(const std::string& name,LogLevel::Level lev){
        return CreatLogger(name,"",lev,LoggerField::LOGGER_LOCAL,LoggerType::LOGGER_SYNC);
    }
    Logger::ptr CreatSyncGlobalLogger(const std::string& name,LogLevel::Level lev){
        return CreatLogger(name,"",lev,LoggerField::LOGGER_GLOBAL,LoggerType::LOGGER_SYNC);
    }
    Logger::ptr CreatAsyncLocalLogger(const std::string& name,LogLevel::Level lev){
        return CreatLogger(name,"",lev,LoggerField::LOGGER_LOCAL,LoggerType::LOGGER_ASYNC);
    }
    Logger::ptr CreatAsyncGLobalLogger(const std::string& name,LogLevel::Level lev){
        return CreatLogger(name,"",lev,LoggerField::LOGGER_GLOBAL,LoggerType::LOGGER_ASYNC);
    }



}
